var appInstance = getApp();
Page({
  data:{
    kefudisplay:true, 
    company:{},
    isSplot:true,
   },
   app_title: '石雕小程序',
  app_description: '石雕小程序',
  page_router: 'companydetail',
  onShareAppMessage: function(){
    var pageRouter = this.page_router;
    var companyId = this.data.company.companyId;
    return {
      title: this.app_title || '石雕小程序',
      desc: this.app_description || '',
      path: '/pages/'+pageRouter+'/'+pageRouter+'?isSplot=false&companyId='+companyId
    }
  },  
  onLoad:function(e){
    console.log(e);
    this.setData({
      companyId:e.companyId
    })
    var that = this;
    appInstance.setPageUserInfo();  
    if(e.isSplot=='false'){that.setData({isSplot:false})}else{that.setData({isSplot:true})}
    if(appInstance.globalData.firstlogin==false){
      that.companyList(e.companyId)
    }    
    // 页面初始化 options为页面跳转所带来的参数
  },
  companyList:function(e){
    return appInstance.companyList(e)
  },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  tapInnerLinkHandler:function(e){
    var params= e.currentTarget.dataset.eventParams;
    console.log(params)
  },
  tofavorite:function(){
    var that = this;
    var company = this.data.company;
    var param = appInstance.globalData.session_key;
    var prodDetail = {
      source : '1',
      userId : param.userId,
      targetId : company.companyId,
      token  : param.myXcxSessionId,
      favoriteDesc:company.name,
      favoriteType:2
    }
    if(company.collectedSign==0){
      appInstance.sendRequest({
        url:'/cust/collectItem',
        data:prodDetail,
        method:'POST',
        success: function(res){
          console.log(res);
          appInstance.showToast({
            title: '收藏成功',
            icon: 'success'
          })
          company.collectedSign=1;
          that.setData({
            company:company
          })
        }
      })
    }else{
      appInstance.sendRequest({
        url:'/cust/cancelCollectItem',
        data:prodDetail,
        method:'POST',
        success: function(res){
          console.log(res);
          appInstance.showToast({
            title: '取消收藏',
            icon: 'success'
          })
          company.collectedSign=0;
          that.setData({
            company:company
          })
        }
      })
    }
  },
  kefu:function(){
    var kefudisplay = this.data.kefudisplay;
     this.setData({
      kefudisplay:!kefudisplay
    })
  },
   content_call:function(e){
    console.log(e)
    return appInstance.makePhoneCall(e)
  },
  navtochange:function(){
     var companyId = this.data.companyId;
      wx.navigateTo({
            url: '../addcompany/addcompany?companyId='+companyId,
            success: function(res){
              // success
            },
          })
  },
  topdf:function(){
    var that = this;
    var company = this.data.company;
    if(company.mobileNo){
    wx.makePhoneCall({
      phoneNumber: company.mobileNo,
      success: function(res) {
        // success
      }
    })
    }else{
      appInstance.showModal({
            content: '供应商没有留号码，请使用其他联系方式'
          });
    }
    // var that = this;
    // var company = this.data.company;
    // var param = appInstance.globalData.session_key;
    // var prodDetail = {
    //   source : '1',
    //   userId : param.userId,
    //   companyId : company.companyId,
    //   token  : param.myXcxSessionId,
    //   fileSource:2,
    // }
    // appInstance.sendRequest({
    //   url:'/prod/genProdAlbum',
    //   data:prodDetail,
    //   method:'POST',           
    //   header:{
    //     'content-type':'application/json'
    //   },
    //   success: function(res){
    //     console.log(res);
    //     wx.downloadFile({
    //       url: res.fileName, 
    //       success: function(res) {
    //         appInstance.showToast({
    //             title: '下载成功',
    //             icon: 'success'
    //         })
    //        }
    //    })     
    //   }
    // })
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})